package com.sang.lesson03;

import com.sang.lesson02.utils.JdbcUtils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class TestSelect {

    public static void main(String[] args) {
        Connection conn = null;
        PreparedStatement st = null;
        ResultSet rs = null;

        try{

            conn = JdbcUtils.getConnection();

            String sql = "SELECT * FROM users WHERE id=?";  //编写SQL

            st = conn.prepareStatement(sql);    //预编译

            st.setInt(1,1);     //传递参数

            rs = st.executeQuery();     //执行

            if (rs.next()){
                System.out.println(rs.getString("NAME"));
            }

            JdbcUtils.release(conn,st,rs);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
